from enum import Enum
from typing import TypeVar, Generic


class ResponseCode(Enum):
    success = 0,
    notLogin = 401,
    notAuthorized = 403,
    notFound = 404,
    badRequest = 400,
    systemError = 500


T = TypeVar('T')


class ResponseAdvice(Generic[T]):
    code: ResponseCode
    message: str
    data: T


def success(data: T) -> ResponseAdvice[T]:
    res = ResponseAdvice()
    res.code = ResponseCode.success
    res.message = 'OK'
    res.data = data
    return res


def not_login(data: T):
    res = ResponseAdvice()
    res.code = ResponseCode.notLogin
    res.message = '请登陆'
    res.data = data
    return res


def not_authorized(data: T):
    res = ResponseAdvice()
    res.code = ResponseCode.notAuthorized
    res.message = '您没有相关权限'
    res.data = data
    return res


def bad_request(message: str):
    res = ResponseAdvice()
    res.code = ResponseCode.badRequest
    res.message = message
    return res
